package com.mtsmda.oracleOfficialTutorialJAVA7.chapter1.nestedClasses;

public class LocalClassEx {

	private static final String PATTERN = "[^0-9]";
	private String name = "name";

	public static void validatePhoneNumbers(String firstNumber,
			String secondNumber) {
		final int numberLenght = 9;

		// int numberLenght = 9; //jdk 8

		class PhoneNumber {
			private String formattedPhoneNumber = null;

			public PhoneNumber(String phoneNumber) {
				// numberLenght = 7; //jdk 8
				String currentNumber = phoneNumber.replaceAll(PATTERN, "");
				if (currentNumber.length() == numberLenght) {
					formattedPhoneNumber = currentNumber;
				} else {
					formattedPhoneNumber = null;
				}
			}

			public String getNumber() {
				return formattedPhoneNumber;
			}

			private void printOriginalNumbers() {
				System.out.println("firstNumber - " + firstNumber);
				System.out.println("secondNumber - " + secondNumber);
			}

		}

		PhoneNumber numberPhoneNumber1 = new PhoneNumber(firstNumber);
		PhoneNumber numberPhoneNumber2 = new PhoneNumber(secondNumber);

		numberPhoneNumber1.printOriginalNumbers();

	}

	public void greetInEnglish() {
	        interface HelloThere {
	           public void greet();
	        }
	        class EnglishHelloThere implements HelloThere {
	            public void greet() {
	                System.out.println("Hello " + name);
	            }
	        }
	        HelloThere myGreeting = new EnglishHelloThere();
	        myGreeting.greet();
	    }

	public void sayGoodbyeInEnglish() {
		class EnglishGoodbye {
			public static void sayGoodbye() {
				System.out.println("Bye bye");
			}
		}
		EnglishGoodbye.sayGoodbye();
	}
	
	public void sayGoodbyeInEnglish1() {
        class EnglishGoodbye {
            public static final String farewell = "Bye bye";
            public void sayGoodbye() {
                System.out.println(farewell);
            }
        }
        EnglishGoodbye myEnglishGoodbye = new EnglishGoodbye();
        myEnglishGoodbye.sayGoodbye();
    }

	public static void main(String[] args) {
		validatePhoneNumbers("069-258-315", "022-359-624");
	}

}